<template>
  <view class="application-container">
    <view class="filter-bar">
      <picker @change="statusChange" :value="statusIndex" :range="statusOptions">
        <view class="filter-item">
          {{ statusOptions[statusIndex] }}
          <uni-icons type="arrowdown" size="14" color="#666"></uni-icons>
        </view>
      </picker>
    </view>

    <view class="application-list">
      <view 
        class="application-item"
        v-for="item in applications"
        :key="item.id"
        :class="item.status"
      >
        <view class="header">
          <text class="school">{{ item.schoolName }}</text>
          <text class="status">{{ statusMap[item.status] }}</text>
        </view>
        <view class="content">
          <view class="info-item">
            <uni-icons type="location" size="16" color="#666"></uni-icons>
            <text>{{ item.location }}</text>
          </view>
          <view class="info-item">
            <uni-icons type="calendar" size="16" color="#666"></uni-icons>
            <text>{{ item.applyDate }}</text>
          </view>
        </view>
        <view class="footer">
          <button 
            class="action-btn" 
            @click="cancelApplication(item.id)"
            v-if="item.status === 'pending'"
          >
            取消申请
          </button>
          <button 
            class="action-btn" 
            @click="viewDetails(item.id)"
          >
            查看详情
          </button>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusIndex: 0,
      statusOptions: ['全部状态', '待处理', '已通过', '已拒绝'],
      statusMap: {
        pending: '审核中',
        approved: '已通过',
        rejected: '已拒绝'
      },
      applications: [
        {
          id: 1,
          schoolName: '阳光希望小学',
          location: '云南丽江',
          applyDate: '2023-07-20',
          status: 'pending',
          details: '申请教授小学三年级数学课程...'
        },
        {
          id: 2,
          schoolName: '山区爱心学校',
          location: '四川凉山',
          applyDate: '2023-07-18',
          status: 'approved',
          details: '暑期英语支教项目...'
        }
      ]
    }
  },
  methods: {
    statusChange(e) {
      this.statusIndex = e.detail.value
    },
    cancelApplication(id) {
      uni.showModal({
        title: '确认取消',
        content: '确定要取消该申请吗？',
        success: (res) => {
          if (res.confirm) {
            // 调用取消申请接口
          }
        }
      })
    },
    viewDetails(id) {
      uni.navigateTo({
        url: `/pages/profile/application-detail?id=${id}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.application-container {
  padding: 30rpx;
  
  .filter-bar {
    margin-bottom: 30rpx;
    
    .filter-item {
      background: #fff;
      border-radius: 40rpx;
      padding: 15rpx 30rpx;
      display: inline-flex;
      align-items: center;
    }
  }
  
  .application-item {
    background: #fff;
    border-radius: 16rpx;
    padding: 30rpx;
    margin-bottom: 20rpx;
    
    &.pending .status {
      color: #5bc0eb;
    }
    &.approved .status {
      color: #4cd964;
    }
    &.rejected .status {
      color: #ff3b30;
    }
    
    .header {
      display: flex;
      justify-content: space-between;
      margin-bottom: 20rpx;
      
      .school {
        font-size: 32rpx;
        color: #2c3e50;
      }
      .status {
        font-size: 26rpx;
      }
    }
    
    .content {
      .info-item {
        display: flex;
        align-items: center;
        margin-bottom: 15rpx;
        color: #666;
        font-size: 26rpx;
        
        uni-icons {
          margin-right: 10rpx;
        }
      }
    }
    
    .footer {
      margin-top: 30rpx;
      display: flex;
      gap: 20rpx;
      
      .action-btn {
        flex: 1;
        background: rgba(91, 192, 235, 0.1);
        color: #5bc0eb;
        border-radius: 40rpx;
        font-size: 26rpx;
        
        &:last-child {
          background: #f5f5f5;
          color: #666;
        }
      }
    }
  }
}
</style> 